package service.impl;

import mapper.StorageRecordMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import entity.StorageRecord;
import service.StorageRecordService;
import utils.Page;

import java.util.List;

@Service("storageRecordService")
@Transactional
public class StorageRecordServiceImpl implements StorageRecordService {
    @Autowired
    private StorageRecordMapper storageRecordMapper;
    @Override
    public boolean add(StorageRecord storageRecord) {
        return storageRecordMapper.add(storageRecord)>0;
    }

    @Override
    public boolean update(StorageRecord storageRecord) {
        return storageRecordMapper.update(storageRecord)>0;
    }

    @Override
    public int delete(Integer id) {
        return storageRecordMapper.delete(id);
    }

    @Override
    public Page<StorageRecord> getPage(StorageRecord storageRecord, Integer pageNo, Integer pageSize) {
        Page<StorageRecord> page = new Page<StorageRecord>();
        page.setPageSize(pageSize);
        // 查询总数，计算总页数
        Integer count = storageRecordMapper.count(storageRecord);
        page.setTotalCount(count);
        page.setPageNo(pageNo);
        List<StorageRecord> data = storageRecordMapper.getPage(storageRecord, page.offset(), page.getPageSize());
        page.setData(data);
        return page;
    }

    @Override
    public StorageRecord getById(Long id) {
        return storageRecordMapper.getById(id);
    }

    @Override
    public StorageRecord getSrCode(String srCode) {
        return storageRecordMapper.getSrCode(srCode);
    }
}
